﻿using AutoMapper;
using MediatR;
using MyMES.Domain.W.Liststructure;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.W.realize;

namespace MyMES.Writer.API.Application.CommendHandlers.W.realize
{
    public class AddSalesReceiptCommandHanders : IRequestHandler<AddSalesReceiptCommands, APIResult<SalesReceipt>>
    {
        private readonly IBaseRepository<SalesReceipt> baseRepository;
        private readonly IMapper mapper;

        public AddSalesReceiptCommandHanders(IBaseRepository<SalesReceipt> baseRepository, IMapper mapper)
        {
            this.baseRepository = baseRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 添加销售出库单信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<SalesReceipt>> Handle(AddSalesReceiptCommands request, CancellationToken cancellationToken)
        {
            APIResult<SalesReceipt> result = new APIResult<SalesReceipt>();
            result.Code = APIEnum.添加成功;
            result.Msg = "添加成功";
            var map = mapper.Map<SalesReceipt>(request);
            var list = "insert into SalesReceipt values (@SalesReceiptId,@OutboundOrderCode,@OutboundOrderName,@SalesOrderNumber,@CustomerCode,@OutboundDate,@DocumentStatus,@Remarks,@CustomerName,@IsDelete)";
            await baseRepository.Insert(map, list);
            return result;
        }
    }
}
